home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / pvga.zip / PVGA.ASM < prev    next >
Assembly Source File  |  1993-01-04  |  6KB  |  217 lines

  1.     page    70,132
  2.     title    PVGA ASM/OBJ: Paradise VGA routines
  3.  
  4. .model TPascal
  5. LOCALS
  6.  
  7. .data
  8.  
  9.     extrn    VideoType:    byte
  10.     extrn    P_VGA:        byte
  11.     extrn    ParadiseRAM:    word
  12.     extrn    Palette256:    byte
  13.     extrn    TextModeNumber:    byte
  14.  
  15.     UnSupported    equ    0    ; These equates are the
  16.     MDA        equ    1    ; equivalent of Turbo Pascal's
  17.     CGA        equ    2    ; "enumerated type".
  18.     EGA        equ    3
  19.     MCGA        equ    4
  20.     VGA        equ    5
  21.     PVGA        equ    6
  22.  
  23. .code
  24.  
  25. ; ______________________________________________
  26. Paradise_Detect proc near
  27. Public Paradise_Detect
  28.         mov        dx,03CEh    ; Graphics Controller Port
  29.         mov        al,9        ; "Bank Select" Register 9
  30.         out        dx,al        ;
  31.         inc        dx        ;
  32.         in        al,dx        ; read current bank
  33.         dec        dx        ;
  34.         or        al,al        ; is current bank zero?
  35.         jnz        @@exit        ; no, therefore no Paradise VGA
  36.         mov        ax,050Fh     ; unlock write access
  37.         out        dx,ax        ;  to extended registers
  38. ; we can compare banks 0 and 1 in text mode (segment B800h)
  39.         mov        di,0B800h    ; point es:di to a
  40.         mov        es,di        ;  byte in video RAM
  41.         xor        di,di        ;   at B800:0000
  42.         mov        bx,0001h    ; compare banks bh=0 and bl=1
  43.         call        bank        ;
  44.         jc        @@exit        ; test failed, not Paradise
  45.         mov        P_VGA,1        ; else this is a Paradise VGA
  46.         mov        ParadiseRAM,256    ; indicate 256k
  47. ; to check banks 0 and 64, we need to be in graphics mode (segment A000)
  48.         mov        ax,0A000h    ;
  49.         mov        es,ax        ;
  50.         mov        ax,005Eh    ; set 
  51.         int        10h        ;   640x400x256 graphics
  52.         mov        bx,0040h    ; compare banks 0 and 64
  53.         call        bank        ;
  54.         pushf                ; push flags
  55.         xor        ah,ah        ; set
  56.         mov        al,TextModeNumber
  57.         int        10h        ;  Text mode
  58.         popf                ; pop flags
  59.         jc        @@exit        ; failed, not 512
  60.         mov        ParadiseRAM,512    ; else 512k
  61. @@exit:                        ;
  62.         ret
  63.  
  64. bank:        mov        ch,11h        ; first test value
  65.         mov        cl,22h        ; second test value
  66.         mov        ah,bh        ; first bank number
  67.         mov        al,9        ; Paradise bank select register
  68.         out        dx,ax        ; select FIRST bank
  69.         xchg        ch,es:[di]    ; swap original and test value
  70.         mov        ah,bl        ; second bank number
  71.         out        dx,ax        ; select SECOND bank
  72.         xchg        cl,es:[di]    ; swap original and test value
  73.         mov        ah,bh        ; bank1
  74.         out        dx,ax        ; select FIRST bank
  75.         xchg        ch,es:[di]    ; swap original back to RAM
  76.         mov        ah,bl        ; bank2
  77.         out        dx,ax        ; select SECOND bank
  78.         xchg        cl,es:[di]    ; swap original back to RAM
  79.         xor        ah,ah        ; bank 0
  80.         out        dx,ax        ; select bank ZERO
  81.         cmp        ch,11h        ; was first value as expected?
  82.         jnz        bankerr        ; no
  83.         cmp        cl,22h        ; check second value.
  84.         jnz        bankerr        ; no
  85.         clc                ; clear carry:
  86.         retn        0        ;  worked as expected
  87. bankerr:    stc                ; set carry:
  88.         retn        0        ;  didn't work
  89. Paradise_Detect endp
  90.  
  91. ;_______________________________________________
  92. Paradise_Unlock proc near
  93. Public Paradise_Unlock
  94.         mov        dx,03CEh    ; Graphics Controller Port
  95.         mov        ax,050Fh     ; unlock write access
  96.         out        dx,ax        ;  to extended registers
  97.         ret
  98. Paradise_Unlock endp
  99.  
  100. ;_______________________________________________
  101. Paradise_Address proc near Row: word, Col: word
  102. Public Paradise_Address
  103.         mov        ax,Row        ; Row number
  104.         mov        cx,640        ; each row is 640 bytes long
  105.         mul        cx        ; dx:ax is address of row
  106.                     ; in the range 0000:0000..0004:AD80
  107.         add        ax,Col        ; adjust the address to row,col
  108.         adc        dx,0        ; dx:ax address = 000H:HLLL
  109.         mov        bx,ax        ; save low order in bx (HLLL)
  110.         and        ax,0FFFh    ; mask low 12 bits ax=0LLL
  111.         mov        di,ax        ;  to di
  112. ; bank switch
  113.         mov        al,bh        ; al=HL
  114.         mov        ah,dl        ; ah=0H   ax=0HHL
  115.         mov        cl,4        ; shift 4 bits
  116.         shr        ax,cl        ; al=HH, the video ram bank
  117.         mov        bl,al        ; save the bank in bl
  118.         mov        dx,03CEh    ; Graphics Controller Port
  119.         mov        ax,050Fh    ; unlock write access
  120.         out        dx,ax        ;   to the extended registers
  121.         mov        al,9        ; PR0A register
  122.         mov        ah,bl        ;   send the bank number
  123.         out        dx,ax        ;     to address extended video
  124.         mov        ax,di        ; return function result in ax
  125.         ret
  126. Paradise_Address endp
  127.  
  128. ;_______________________________________________
  129. SetVideoMode_ proc near Mode: byte, TextLines: word
  130. Public SetVideoMode_
  131.         mov        ax,40h        ; "info byte"
  132.         mov        es,ax        ; at 40h:87h
  133.         and byte ptr    es:[87h],0FEh    ; turn OFF "alphanumeric cursor
  134.                         ;    emulation"
  135.         xor        ah,ah        ; function 0 = set mode
  136.         mov        al,Mode        ;
  137.         int        10h        ;
  138.         cmp        TextLines,43    ; set 43 lines?
  139.         jnz        S50        ;
  140.         cmp        VideoType,EGA    ; 43 line EGA mode?
  141.         jnz        @@exit        ;
  142.         mov        ax,1112h    ; character generator 8x8 font
  143.         xor        bl,bl        ;
  144.         int        10h        ; load 8x8 font
  145.         or byte ptr    es:[87h],1    ; turn ON emulation
  146.         mov        ax,0100h    ; set cursor size
  147.         mov        cx,0600h    ; size to set
  148.         int        10h        ;
  149.         mov        ah,12h        ; alternate select
  150.         mov        bl,20h        ; select alternate PrtScr
  151.         int        10h        ;
  152.         jmp short    @@exit        ;
  153. S50:        cmp        TextLines,50    ; set 50 lines?
  154.         jnz        @@exit        ; no
  155.         mov        ax,1112h    ; character generator 8x8 font
  156.         xor        bl,bl        ;
  157.         int        10h        ; load 8x8 font
  158. @@exit:        ret
  159. SetVideoMode_ endp
  160.  
  161. ;_______________________________________________
  162. ClearTextScreenAndSetBorder proc near X: byte, Y: byte, A: byte, B: byte
  163. Public ClearTextScreenAndSetBorder
  164.         mov        ax,0600h    ; scroll up 0 lines = ClrScr
  165.         mov        bh,A        ; video attribute
  166.         xor        cx,cx        ; upper left = 0,0
  167.         mov        dh,Y        ; lower right: row
  168.         dec        dh        ;  adjust relative to 0
  169.         mov        dl,X        ; lower right: column
  170.         dec        dl        ;  adjust relative to 0
  171.         int        10h        ; Video interrupt
  172.         cmp        VideoType,MDA    ; MDA?
  173.         jz        @@exit        ;  then no border
  174.         cmp        VideoType,EGA    ; EGA?
  175.         jz        @@exit        ;  then no border
  176.         cmp        VideoType,CGA    ; CGA?
  177.         jnz        SB1        ;
  178. ; set CGA border color
  179.         mov        ax,0B00h    ; set palette function
  180.         mov        bh,0        ; bh=0 sets CGA border color
  181.         mov        bl,B        ; bl is color to use
  182.         int        10h        ;
  183.         jmp short    @@exit        ;
  184. ; set MCGA/VGA border color
  185. SB1:        mov        ax,1001h    ; set overscan (border) reg
  186.         mov        bh,B        ; border color
  187.         int        10h        ; Video interrupt
  188. @@exit:        ret
  189. ClearTextScreenAndSetBorder endp
  190.  
  191. ;_______________________________________________
  192. SetMCGAPalette proc near
  193. Public SetMCGAPalette
  194.         mov        ax,ds        ; move ds
  195.         mov        es,ax        ;  to es
  196.         lea        dx,Palette256[32*3] ; es:dx -> P[32]
  197.         mov        bx,32        ; first to set is #32
  198.         mov        cx,224        ; set 224 (32..255)
  199.         mov        ax,1012h    ; Set a block of DAC regs
  200.         int        10h        ; Video interrupt
  201.         ret
  202. SetMCGAPalette endp
  203.  
  204. ;_______________________________________________
  205. SetEgaWriteMode proc near Mode: byte
  206. Public SetEgaWriteMode
  207.         mov        dx,03CEh    ; EGA index port
  208.         mov        al,5        ; graphics mode register
  209.         out        dx,al        ;
  210.         inc        dx        ;
  211.         mov        al,Mode        ; mode to set
  212.         out        dx,al        ;
  213.         ret
  214. SetEgaWriteMode endp
  215.  
  216.     end
  217.